<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>专业化评价预警工具 - 修改密码</title>
    <style>
        /* 保留原有的样式 */
        .container {
            background-color: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
            position: relative;
            overflow: hidden;
        }
        .container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background-color: #2a9d8f;
        }
        .container::after {
            content: '';
            position: absolute;
            top: -50px;
            right: -50px;
            width: 100px;
            height: 100px;
            background-color: rgba(42, 157, 143, 0.1);
            border-radius: 50%;
        }
        h1 {
            color: #333;
            margin-bottom: 1.5rem;
            font-size: 1.75rem;
            text-align: center;
        }
        .input-group {
            margin-bottom: 1.25rem;
            position: relative;
        }
        label {
            display: block;
            margin-bottom: 0.5rem;
            color: #555;
            font-size: 0.9rem;
        }
        input[type="text"],
        input[type="password"],
        input[type="email"] {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 1rem;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        input[type="text"]:focus,
        input[type="password"]:focus,
        input[type="email"]:focus {
            outline: none;
            border-color: #2a9d8f;
            box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.2);
        }
        .form-switch {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
            font-size: 0.9rem;
        }
        .form-switch a {
            color: #2a9d8f;
            text-decoration: none;
            transition: color 0.3s;
        }
        .form-switch a:hover {
            color: #238b7e;
            text-decoration: underline;
        }
        .submit-button {
            width: 100%;
            padding: 0.75rem;
            background-color: #2a9d8f;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 1rem;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.1s;
        }
        .submit-button:hover {
            background-color: #238b7e;
        }
        .submit-button:active {
            transform: translateY(1px);
        }
        .system-info {
            margin-top: 2rem;
            padding-top: 1rem;
            border-top: 1px solid #eee;
            text-align: center;
            color: #777;
            font-size: 0.875rem;
        }
        @media (max-width: 480px) {
            .container {
                padding: 1.5rem;
            }
            h1 {
                font-size: 1.5rem;
            }
        }
        .hidden {
            display: none;
        }
        .delete-button {
            background-color: #e63946;
        }
        .delete-button:hover {
            background-color: #d62828;
        }
    </style>
</head>
<body>
<div id="modification_div" style="position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);width: 400px;display: none">
    <div class="container">


        <div id="forgotPasswordForm">
            <h1>专业化评价预警工具 - 修改密码</h1>
            <form @submit.prevent="submit">
                <div class="input-group">
                    <label for="forgotPasswordUsername">用户名</label>
                    <input type="text" id="forgotPasswordUsername" name="username" placeholder="请输入要修改的用户名" required>
                </div>
                <div class="input-group">
                    <label for="newPassword">密码</label>
                    <input type="password" id="Password1" name="Password" placeholder="请输入原密码" required>
                </div>
                <div class="input-group">
                    <label for="newPassword">新密码</label>
                    <input type="password" id="newPassword" name="newPassword" placeholder="请输入新密码" required>
                </div>
                <div class="input-group">
                    <label for="confirmNewPassword">确认新密码</label>
                    <input type="password" id="confirmNewPassword" name="confirmNewPassword" placeholder="请再次输入新密码" required>
                </div>
                <div class="form-switch">
                    <a href="#" onclick="showLoginForm()">返回首页</a>
                </div>
                <button type="submit" class="submit-button">修改密码</button>
            </form>
        </div>

        <div class="system-info">
            专业化评价预警工具
        </div>
    </div>
</div>
<script src="${ROOT}/mind/js/vue2.js"></script>
<link href="${ROOT}/mind/css/element-ui.css" rel="stylesheet">
<!-- 引入Element Plus的JavaScript -->
<script src="${ROOT}/mind/js/element-ui.js"></script>
<script>
    new Vue({
        el: '#modification_div',
        methods:{
            submit(){
                    const username = document.getElementById('forgotPasswordUsername').value;
                    const newPassword = document.getElementById('newPassword').value;
                    const Password1 = document.getElementById('Password1').value;
                    const confirmNewPassword = document.getElementById('confirmNewPassword').value;

                    if (newPassword !== confirmNewPassword) {
                        this.$message({
                            message: '两次输入的新密码不一致，请重新输入！',
                            type: 'error'
                        });
                        return;
                    }

                    let url='http://127.0.0.1:8001/mp?u='+username+'&p='+Password1+'&np='+newPassword
                    fetch(url)
                        .then(response => response.json())
                        .then(data => {
                            if (data.code == 0) {
                                this.$message({
                                    message: '密码重置成功，请使用新密码登录',
                                    type: 'success'
                                });
                                document.getElementById('modification_div').style.display = 'none'
                                document.getElementById('login_div').style.display = 'block'
                                sessionStorage.clear()
                            } else if(data.code == 1){
                                this.$message({
                                    message: '用户名或密码错误',
                                    type: 'error'
                                });
                            } else if(data.code == 2){
                                this.$message({
                                    message: '数据库错误',
                                    type: 'error'
                                });
                            } else if(data.code == 3){
                                this.$message({
                                    message: '密码格式错误，密码需要有大写字母、小写字母、特殊符号和数字，不能小于8位',
                                    type: 'error'
                                });
                            }  else {
                                this.$message({
                                    message: '密码重置失败，请稍后再试',
                                    type: 'error'
                                });
                            }
                        })
                        .catch(error => {
                            this.$message({
                                message: '密码重置请求出错，请稍后再试',
                                type: 'error'
                            });
                        });
            }
        }
    })
    function  showLoginForm(){
        document.getElementById('loginDiv').style.display = 'none'
    }
</script>
</body>
</html>